package com.wondertek.common.util.security;

import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Set;

@Service(value = "el")
public class ElPermissionConfig {

    public Boolean check(String... permissions) {
        // 获取当前用户的所有权限
        LoginUser loginUser = SecurityUtil.SecurityContext.get();
        if (null != loginUser) {
            Set<String> authoritiesButton = loginUser.getAuthoritiesButton();
            // 检查用户是否具有所需权限
            return authoritiesButton.contains("admin") || Arrays.stream(permissions).anyMatch(authoritiesButton::contains);
        }
        return false;
    }
}
